clear all
global system "linux"

if "${system}" == "linux" {
	*global code "/"
	global code "/"
	global s "/"
}

run "${code}${s}_set-path.do"

cd "${code}/tba_elig"

*** 1. Run regressions

local flist1: dir "${Estimates}" files "hetero*.ster"
foreach f in `flist1'  {
	cap erase "${Estimates}/`f'"
}
local flist: dir "${log}" files "*"
foreach f of local flist {
	cap erase "${log}/`f'"
}

*** 2. Run regressions
local cmd "sbatch -export=HOME,PATH,SHELL -a 1-4 embs-lps-hetero.sh" 
di "`cmd'"

local JobIdFile "${log}/job-id.csv"  
log using `JobIdFile', name("jobid") text replace
shell `cmd'
log close _all

do _sbatch-job "`JobIdFile'"



*** 3. create tables
clear

run _esttab-latex-options.do

set obs 1
gen PaboveC = 1
gen Cutoff = 1
gen notba = 1

foreach x in prime NoNY NoNYTXFL {
	gen notba_`x' = 1
}

eststo clear

foreach n of numlist 1/2 {
	est use "${Estimates}/embs-lps-hetero`n'"
	eststo
	
	estadd local Zip "Y"
	estadd local Lender "Y"
	estadd local Month "Y"
	estadd local control "Y"
}


run "${code}/_labels"

esttab using "${table}/embs-lps-hetero.tex", replace keep(notba*) ///
 ${opts_esttab} nodepvar nomtitle b(%9.3fc) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
 stats(Zip Month Lender control N r2_a, fmt(%1s %1s %1s %1s %9.0fc %3.2f) ///
 labels("Zipcode FE" "Lender FE" "Month FE" "Other Controls" "\midrule N. Obs." "Adj. $ R^2$")) 
